package l1j.server.server.clientpackets;

import java.util.logging.Logger;
import java.util.logging.Level;

import l1j.server.echo.ClientThread;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_ChangeHeading;

/**
 * 收到由客戶端傳來改變面向的封包
 */
public class C_ChangeHeading extends ClientBasePacket {
	private static final String C_CHANGE_HEADING = "[C] C_ChangeHeading";
	private static Logger _log = Logger.getLogger(C_ChangeHeading.class.getName());
	@Override
	public String getType() {
		return C_CHANGE_HEADING;
	}

	@Override
	public void start(final byte[] decrypt, final ClientThread client) {
		try {
			// 資料載入
			this.read(decrypt);

		final L1PcInstance pc = client.getActiveChar();
		if (pc == null) {
			return;
		}
		final int heading = this.readC();
		pc.setHeading(heading);
		_log.finest("Change Heading : " + pc.getHeading());

		if (pc.isGmInvis() || pc.isGhost()) {
		} else if (pc.isInvisble()) {
			pc.broadcastPacketForFindInvis(new S_ChangeHeading(pc), true);
		} else {
			pc.broadcastPacketAll(new S_ChangeHeading(pc));
		}
		} catch (final Exception e) {
			_log.log(Level.SEVERE, e.getLocalizedMessage(), e);

		} finally {
			this.over();
		}
	}
}